﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoiceMessager.Stream.Cmd;

namespace VoiceMessager.Stream
{
	public static class CmdFactory
	{
		public static CmdStream CreateStream(CmdCommand command,CmdCommandParam param = CmdCommandParam.Gb2312,byte[] data =null)
		{
			var stream = new CmdStream
			{
				Header = 0xfd,
				Command = (byte) command
			};
			if (command == CmdCommand.PlayVoice)
			{
				if (data == null) throw new ArgumentNullException();
				var lb = BitConverter.GetBytes(data.Length+2);
				stream.DataLength = new[] {lb[1], lb[0]};
				stream.SendData = data;
				stream.CommandParam = new[] { (byte)param };
			}
			else
			{
				stream.DataLength = new byte[] { 0x00, 0x01 };
				stream.CommandParam = new byte[0];
				stream.SendData = new byte[0];
			}
			return stream;
		}
	}
}
